<!-- 商品详情页 -->
<template>
	<view>
		<!-- 商品图片 -->
		<view class="img">
			<u-image width="300rpx" height="300rpx" :src="goodsInfo.cover_url"></u-image>
		</view>
		<!-- 商品标题 -->
		<view class="title">{{goodsInfo.title}}</view>
		
		<view class="u-flex u-row-between u-m-b-20 u-m-t-20">
			<view class="price u-m-l-40">￥{{goodsInfo.price}}</view>
			<view class="sales u-m-r-40">销量 {{goodsInfo.sales}}</view>
		</view>
		<!-- 菜单 -->
		<u-tabs :list="list" :is-scroll="false" :current="current" @change="change"></u-tabs>
		<!-- 商品详情 -->
		<view v-if="current==0">
			<view class="">
					<u-parse :html="goodsInfo.details"></u-parse>
			</view>
		</view>
		<!-- 商品评论 -->
		<view v-if="current==1">
			<view class="">
				<view class="comment" v-for="(res, index) in commentList" :key="res.id">
					<view class="left"><image :src="res.user.avatar_url" mode="aspectFill"></image></view>
					<view class="right">
						<view class="top">
							<view class="name">{{ res.user.name }}</view>
							
						</view>
						<view class="content">{{ res.content }}</view>
						
						<view class="bottom">
							{{ res.created_at }}
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 推荐商品 -->
		<view v-if="current==2">
			<u-row gutter="16">
				<u-col v-for="goods in goods" span="6">
					<goods-card :goods="goods"></goods-card>
				</u-col>
			</u-row>
			
		</view>
		<!-- 底部菜单 -->
		<view class="navigation">
			<view class="left">
				<view class="item">
					<u-icon name="server-fill" :size="40" :color="$u.color['contentColor']"></u-icon>
					<view class="text u-line-1">客服</view>
				</view>
				<view class="item">
					<u-icon name="home" :size="40" :color="$u.color['contentColor']"></u-icon>
					<view class="text u-line-1">店铺</view>
				</view>
				<view class="item car">
					<u-badge class="car-num" :count="9" type="error" :offset="[-3, -6]"></u-badge>
					<u-icon name="shopping-cart" :size="40" :color="$u.color['contentColor']"></u-icon>
					<view class="text u-line-1">购物车</view>
				</view>
			</view>
			<view class="right">
				<view class="cart btn u-line-1">加入购物车</view>
				<view class="buy btn u-line-1">立即购买</view>
			</view>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				src: 'https://oss.shop.eduwork.cn/product/2020-0820-5f3e17d6ed7e8.png',
				list: [{
					name: '商品详情'
				}, {
					name: '商品评论'
				}, {
					name: '推荐商品',
					count: 5
				}],
				current: 0,
				content: "",
				commentList: [],
				goodsInfo:{},
				goods:[],
				goodsId:null,
				
			}
		},
		onLoad(option) {	
			this.goodsId=option.id;
			console.log(option.id);
			this.getData();		
			},
		methods: {
			//切换菜单内容
			change(index) {
				this.current = index;
			},
			//请求数据
			async getData(){
				console.log(this.goodsId);
				const res = await this.$u.api.goodsInfo(this.goodsId).then(res=>{
					console.log(res);
					this.goodsInfo=res.goods;
					this.commentList=res.goods.comments;
					this.goods=res.like_goods;
				});
				
			},
			
			
		}
	}
</script>

<style lang="scss" scoped>
	.img {
		display: flex;
		flex-direction: row;
		justify-content: center;
		width: 100%;
		height: 320rpx;
	}

	.title {
		font-weight: bold;
		font-size: 40rpx;
		margin-left: 50rpx;
	}

	.price {
		color: red;
		font-weight: bold;
	}

	.sales {
		color: #888;
	}

	.navigation {
		height: 90rpx;
		position: fixed;
		bottom: 0rpx;
		display: flex;
		margin-top: 600rpx;
		border: solid 2rpx #f2f2f2;
		background-color: #ffffff;
		padding: 16rpx 0;

		.left {
			display: flex;
			font-size: 20rpx;

			.item {
				margin: 0 30rpx;

				&.car {
					text-align: center;
					position: relative;

					.car-num {
						position: absolute;
						top: -10rpx;
						right: -10rpx;
					}
				}
			}
		}

		.right {
			display: flex;
			font-size: 28rpx;
			align-items: center;

			.btn {
				line-height: 66rpx;
				padding: 0 30rpx;
				border-radius: 36rpx;
				color: #ffffff;
			}

			.cart {
				background-color: #ed3f14;
				margin-right: 30rpx;
			}

			.buy {
				background-color: #ff7900;
			}
		}
	}
	.comment {
		display: flex;
		padding: 30rpx;
		.left {
			image {
				width: 64rpx;
				height: 64rpx;
				border-radius: 50%;
				background-color: #f2f2f2;
			}
		}
		.right {
			flex: 1;
			padding-left: 20rpx;
			font-size: 30rpx;
			.top {
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-bottom: 10rpx;
				.name {
					color: #5677fc;
				}
				.like {
					display: flex;
					align-items: center;
					color: #9a9a9a;
					font-size: 26rpx;
					.num {
						margin-right: 4rpx;
						color: #9a9a9a;
					}
				}
				.highlight {
					color: #5677fc;
					.num {
						color: #5677fc;
					}
				}
			}
			.content {
				margin-bottom: 10rpx;
			}
			.reply-box {
				background-color: rgb(242, 242, 242);
				border-radius: 12rpx;
				.item {
					padding: 20rpx;
					border-bottom: solid 2rpx $u-border-color;
					.username {
						font-size: 24rpx;
						color: #999999;
					}
				}
				.all-reply {
					padding: 20rpx;
					display: flex;
					color: #5677fc;
					align-items: center;
					.more {
						margin-left: 6rpx;
					}
				}
			}
			.bottom {
				margin-top: 20rpx;
				display: flex;
				font-size: 24rpx;
				color: #9a9a9a;
				.reply {
					color: #5677fc;
					margin-left: 10rpx;
				}
			}
		}
	}
</style>
